#include <assert.h>
#include <stdlib.h>

// MACA runtime
#include <mcblas/mcblas.h>
#include <mc_runtime.h>

#include "helper.h"


// MACA and mcBlas functions

void SGEMM_GPU_REF(mcblasHandle_t handle, int m, int n, int k, float *d_A, float *d_B, float *d_C) {

  const float alpha = 1.0f;
  const float beta = 0.0f;
  // checkGPUErrors(mcblasGemmEx(handle, MCBLAS_OP_T, MCBLAS_OP_T,
  //                     m, n, k,
  //                     &alpha,
  //                     d_A, MACA_R_32F, k,
  //                     d_B, MACA_R_32F, n,
  //                     &beta,
  //                     d_C, MACA_R_32F, n,   // this leads to col-major C
  //                     MACA_R_32F, MCBLAS_GEMM_DEFAULT_TENSOR_OP));
  checkGPUErrors(mcblasGemmEx(handle, MCBLAS_OP_N, MCBLAS_OP_N, 
                        n, m, k,
                        &alpha,
                        d_B, MACA_R_32F, n,
                        d_A, MACA_R_32F, m,
                        &beta,
                        d_C, MACA_R_32F, n,
                        MACA_R_32F, MCBLAS_GEMM_DEFAULT_TENSOR_OP));
  /* mcBlas assumes column-major order. To work with row-major matrices in mcBLAS, 
  you should transpose the matrices while performing the operation. This means if 
  you want to compute C = A * B (where C, A, and B are all row-major), you should 
  actually compute C^T = B^T * A^T in mcBLAS.
  Since C^T is the transpose of the desired matrix C, and since mcBlas will naturally 
  output in column-major order, the result will be in the correct row-major order 
  without needing to transpose it back.*/
}
